#!/usr/bin/env python
# -*- coding: utf8 -*-
# title       :
# description :
# author      :'ShenMeng'

from PySide import QtGui, QtCore
from .baseui.movewidget import MoveWidget
from .pyuic.title_bar_widget import Ui_title_bar_widget
class TitleBarWidget(MoveWidget):#QtGui.QWidget):
    def __init__(self, parent=None):
        super(TitleBarWidget, self).__init__(parent)
        self._ui = Ui_title_bar_widget()
        self._ui.setupUi(self)
        # self._ui.logo.setPixmap(':/icons/ver_logo_all.png')
        # self._ui.logo.setText(u'软件中心')
        # 初始化参数
        self._parent = parent
        # 无边框透明
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowSystemMenuHint)
        # self.setAttribute(Qt.WA_TranslucentBackground)
        self.setWindowOpacity(0)
        self.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Fixed)
        self.maxNormal=False
        self.setMinimumWidth(300)
        self._ui.close_btn.clicked.connect(self._on_close_btn_clicked)
        self._ui.min_btn.clicked.connect(self._on_min_btn_clicked)
        #self.max_btn.clicked.connect(self._on_max_btn_clicked)

    def _on_min_btn_clicked(self):
        self._parent.showMinimized()

    def _on_max_btn_clicked(self):
        if(self.maxNormal):
            self._parent.showNormal()
            self.maxNormal= False
        else:
            self._parent.showMaximized()
            self.maxNormal=  True

    def _on_close_btn_clicked(self):
        self._parent.close()
